<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\SchemeRobotRequest;
use App\CustHub\Service\ChOpSchemeRobotService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

#[Controller(prefix: 'ch/opSchemeRobot'),ApiAuth,VerifySignature]
class OpSchemeRobotController extends BaseController
{
    #[Inject]
    protected ChOpSchemeRobotService $service;

    /**
     * 列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(SchemeRobotRequest $request): ResponseInterface
    {
        return $this->success($this->service->list($request->all()));
    }

    /**
     * 改版状态
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('batchChangeStatus'),ChOperationLog]
    public function batchChangeStatus(SchemeRobotRequest $request): ResponseInterface
    {
        return $this->service->batchChangeStatus($request->all()) ? $this->success(): $this->error();
    }

    /**
     * 取消应用
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('cancel'),ChOperationLog]
    public function cancel(SchemeRobotRequest $request): ResponseInterface
    {
        return $this->service->batchCancel($request->all()) ? $this->success(): $this->error();
    }

    /**
     * 应用记录
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('record')]
    public function record(SchemeRobotRequest $request): ResponseInterface
    {
        return $this->success($this->service->record($request->all()));
    }

    /**
     * 应用方案
     * @param SchemeRobotRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChOperationLog]
    public function applicationScheme(SchemeRobotRequest $request): ResponseInterface
    {
        return $this->service->applicationScheme($request->all()) ? $this->success() : $this->error();
    }
}